package ronglei.heima.day01;

import java.util.Random;
import java.util.Scanner;

// 随机数
public class Demo04Random {
    public static void main(String[] args) {
        Random r = new Random();
        int number = r.nextInt(10); //0 -- 9
        System.out.println(number);
//////////////////////////////////////////////
//        猜数字

        Random s = new Random(); //随机数
        Scanner sc = new Scanner(System.in); //键盘录入
//        产生1-100的随机数
        int randomNum = r.nextInt(100) + 1;
        while (true) {
            System.out.println("请输入您猜的数据：");
            //键盘录入
            int num = sc.nextInt();
            if (num > randomNum) {
                System.out.println("你猜大了");
            } else if (num < randomNum) {
                System.out.println("您猜小了");
            } else {
                System.out.println("猜中了");
                break;
            }
        }

    }
}
